package cfgs.gestudent.finestra.assistencia;

import java.awt.Color;

import javax.swing.JPanel;

import java.awt.GridBagLayout;

import javax.swing.JButton;

import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.ResourceBundle;

import javax.swing.ButtonGroup;
import javax.swing.JLabel;
import javax.swing.JComboBox;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.JFormattedTextField;
import javax.swing.JRadioButton;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.JTable;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;

import org.freixas.jcalendar.JCalendarCombo;

import com.sun.glass.ui.MenuItem;
import com.sun.webkit.PopupMenu;

import cfgs.gestudent.dao.alumnes.EliminarAlumne;
import cfgs.gestudent.dao.alumnes.TaulaControladoraModificacions;
import cfgs.gestudent.dao.assignatures.EliminarAssignatura;
import cfgs.gestudent.dao.assignatures.TaulaControladoraModificacionsAssignatura;
import cfgs.gestudent.dao.assistencia.MostrarAlumneAssis;
import cfgs.gestudent.dao.assistencia.MostrarAssignaturaAssis;
import cfgs.gestudent.dao.curs.EliminarImpartirAssignatura;
import cfgs.gestudent.dao.curs.InserirAssistencia;
import cfgs.gestudent.preferencies.ConfiguracionsIdiomes;
import cfgs.gestudent.preferencies.PreferenciesAnyAcademic;
import java.awt.Font;

public class FinestraInserirAssitenciaManual extends JPanel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 111295460159191107L;
	
	private JScrollPane scrollComen;
	private JScrollPane scrollAlum;
	private JScrollPane scrollAssign;
	private JTable tableAlum;
	private JTable tableAssign;
	private DefaultTableModel dtmEjemplo;
	private DefaultTableModel dtmAssignatura;
	
	private ConfiguracionsIdiomes configs = new ConfiguracionsIdiomes();
	private ResourceBundle rb = configs.getIdioma();
	
	private JPopupMenu popupMenu;
	private JMenuItem mntmBorrar;
	
	private JPopupMenu popupMenuAssign;
	private JMenuItem mntmBorrarAssign;
	
	private MostrarAlumneAssis maa;
	private MostrarAssignaturaAssis masa;
	
	private JTextField txtHora;
	
	private JRadioButton rdbtnAssistit;
	private JRadioButton rdbtnRetard;
	private JRadioButton rdbtnFalta;
	private JRadioButton rdbtnFaltaJustificada;
	
	private JCalendarCombo comboDia;
	
	private int idAlum = 0;
	private String fecha;
	private JTextPane textPane;
	private String horaAct=null;
	
	/**
	 * Create the panel.
	 */
	public FinestraInserirAssitenciaManual() {
		
		setBackground(Color.WHITE);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 119, 0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		/**
		 * Taula alumne
		 */
		JLabel lblAlumne = new JLabel(rb.getString("lblAlumne"));
		lblAlumne.setFont(new Font("Tahoma", Font.BOLD, 12));
		GridBagConstraints gbc_lblAlumne = new GridBagConstraints();
		gbc_lblAlumne.insets = new Insets(0, 0, 5, 5);
		gbc_lblAlumne.gridx = 0;
		gbc_lblAlumne.gridy = 0;
		add(lblAlumne, gbc_lblAlumne);
		
		tableAlum = new JTable();
		scrollAlum = new JScrollPane();
		scrollAlum.setViewportView(tableAlum);
		maa = new MostrarAlumneAssis();
		maa.setSql("SELECT al.Nom AS Noms, al.Cognoms AS Cognoms, c.Nom AS Curs, gc.Nom AS Grup, al.Id AS Id, c.Id, gc.Id FROM ALUMNE al, GRUP_CURS gc, CURS c, ANY_ACADEMIC aa WHERE al.Id_Grup_Curs=gc.Id AND gc.Id_Curs=c.Id AND aa.Id=c.Id_Any_Academic AND aa.Id="+veureIdAnyAncademic()+" ORDER BY c.Id, gc.Id, Cognoms ASC ");
		dtmEjemplo = new DefaultTableModel(maa.getFilas(), maa.getColumnas()){
			@Override
		    public boolean isCellEditable (int row, int column)
		    {
				if (column == 0)
			           return true;
			        
			    if(column == 1)
			        	return true;
			    
			    if (column == 2)
		           return false;
		        
		        if(column == 3)
		        	return false;
		        			
		        return false;
		    }
		};
		tableAlum.setModel(dtmEjemplo);
		tableAlum.getColumnModel().getColumn(0).setCellEditor(new TaulaControladoraModificacions(maa.getFilas(), "Nom", 4));
		tableAlum.getColumnModel().getColumn(1).setCellEditor(new TaulaControladoraModificacions(maa.getFilas(), "Cognoms", 4));
		tableAlum.getColumnModel().getColumn(3).setCellEditor(new TaulaControladoraModificacions(maa.getFilas(), "Id_Grup_Curs", 6));
		
		popupMenu = new JPopupMenu();
		addPopup(tableAlum, popupMenu);
		
		mntmBorrar = new JMenuItem(rb.getString("borrar"));
		mntmBorrar.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				int row = tableAlum.getSelectedRow();
				Object [][] obj = maa.getFilas();
				int idBorrar = (int) obj[row][4];
				EliminarAlumne ea = new EliminarAlumne();
				ea.eliminarRegistre(idBorrar, tableAlum.getValueAt(row, 0).toString()+" - "+tableAlum.getValueAt(row, 1).toString());
				maa.setSql("SELECT al.Nom AS Noms, al.Cognoms AS Cognoms, c.Nom AS Curs, gc.Nom AS Grup, al.Id AS Id, c.Id, gc.Id FROM ALUMNE al, GRUP_CURS gc, CURS c, ANY_ACADEMIC aa WHERE al.Id_Grup_Curs=gc.Id AND gc.Id_Curs=c.Id AND aa.Id=c.Id_Any_Academic AND aa.Id="+veureIdAnyAncademic()+" ORDER BY c.Id, gc.Id, Cognoms ASC ");
				dtmEjemplo = new DefaultTableModel(maa.getFilas(), maa.getColumnas()){
					@Override
				    public boolean isCellEditable (int row, int column)
				    {
						if (column == 0)
					           return true;
					        
					    if(column == 1)
					        	return true;
					    
					    if (column == 2)
				           return false;
				        
				        if(column == 3)
				        	return false;
				        			
				        return false;
				    }
				};
				tableAlum.setModel(dtmEjemplo);
				/**
				 * Modificar 
				 */
				tableAlum.getColumnModel().getColumn(0).setCellEditor(new TaulaControladoraModificacions(maa.getFilas(), "Nom", 4));
				tableAlum.getColumnModel().getColumn(1).setCellEditor(new TaulaControladoraModificacions(maa.getFilas(), "Cognoms", 4));
				tableAlum.getColumnModel().getColumn(3).setCellEditor(new TaulaControladoraModificacions(maa.getFilas(), "Id_Grup_Curs", 6));
			}
		});
		popupMenu.add(mntmBorrar);
		
		GridBagConstraints gbc_table = new GridBagConstraints();
		gbc_table.gridwidth = 5;
		gbc_table.insets = new Insets(0, 0, 5, 0);
		gbc_table.fill = GridBagConstraints.BOTH;
		gbc_table.gridx = 0;
		gbc_table.gridy = 1;
		add(scrollAlum, gbc_table);
		tableAlum
				.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

		// filtro per taula assign
		ListSelectionModel cellSelect = tableAlum.getSelectionModel();
		cellSelect.addListSelectionListener(new ListSelectionListener() {

			@Override
			public void valueChanged(ListSelectionEvent arg0) {
				int row = tableAlum.getSelectedRow();
				Object[][] obj = maa.getFilas();
				idAlum = (int) obj[row][4];
				
				String sqlAS = "SELECT c.Nom, gc.Nom, a.Nom, d.Nom, ia.Hora_Inici, ia.Hora_Fi, ia.Id"
						+" FROM IMPARTIR_ASSIGNATURA ia, ASSIGNATURA a, GRUP_CURS gc, CURS c, ANY_ACADEMIC aa, DIES d, ALUMNE al"
						+" WHERE ia.Id_Assignatura=a.Id AND ia.Id_Grup_Curs=gc.Id AND gc.Id_Curs=c.Id AND c.Id_Any_Academic=aa.Id AND ia.Id_Dies=d.Id"
						+" AND aa.Id="+veureIdAnyAncademic()
						+" AND al.Id_Grup_Curs=gc.Id"
						+" AND al.Id="+idAlum
						+" GROUP BY ia.Id"
						+" ORDER BY c.Id, gc.Id, a.Id, d.Id, ia.Hora_Inici, ia.Hora_Fi";;
				
				masa = new MostrarAssignaturaAssis();
				masa.setSql(sqlAS);
				dtmAssignatura = new DefaultTableModel(masa.getFilas(), masa.getColumnas()){
					@Override
				    public boolean isCellEditable (int row, int column)
				    {
				        			
				        return false;
				    }
				};
				tableAssign.setModel(dtmAssignatura);
			}
		});

		/**
		 * Taula assignatura
		 */
		JLabel lblAssignatura = new JLabel(rb.getString("lblAssignaturaAssis"));
		lblAssignatura.setFont(new Font("Tahoma", Font.BOLD, 12));
		GridBagConstraints gbc_lblAssignatura = new GridBagConstraints();
		gbc_lblAssignatura.insets = new Insets(0, 0, 5, 5);
		gbc_lblAssignatura.gridx = 0;
		gbc_lblAssignatura.gridy = 2;
		add(lblAssignatura, gbc_lblAssignatura);
		
		final String sqlAS = "SELECT c.Nom, gc.Nom, a.Nom, d.Nom, ia.Hora_Inici, ia.Hora_Fi, ia.Id"
				+" FROM IMPARTIR_ASSIGNATURA ia, ASSIGNATURA a, GRUP_CURS gc, CURS c, ANY_ACADEMIC aa, DIES d"
				+" WHERE ia.Id_Assignatura=a.Id AND ia.Id_Grup_Curs=gc.Id AND gc.Id_Curs=c.Id AND c.Id_Any_Academic=aa.Id AND ia.Id_Dies=d.Id"
				+" AND aa.Id="+veureIdAnyAncademic()
				+" GROUP BY ia.Id"
				+" ORDER BY c.Id, gc.Id, a.Id, d.Id, ia.Hora_Inici, ia.Hora_Fi";;
		
		tableAssign = new JTable();
		scrollAssign = new JScrollPane();
		scrollAssign.setViewportView(tableAssign);
		masa = new MostrarAssignaturaAssis();
		masa.setSql(sqlAS);
		dtmAssignatura = new DefaultTableModel(masa.getFilas(), masa.getColumnas()){
			@Override
		    public boolean isCellEditable (int row, int column)
		    {
		        			
		        return false;
		    }
		};
		tableAssign.setModel(dtmAssignatura);
		
		GridBagConstraints gbc_table_1 = new GridBagConstraints();
		gbc_table_1.gridwidth = 5;
		gbc_table_1.insets = new Insets(0, 0, 5, 0);
		gbc_table_1.fill = GridBagConstraints.BOTH;
		gbc_table_1.gridx = 0;
		gbc_table_1.gridy = 3;
		add(scrollAssign, gbc_table_1);
		tableAssign.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
		
		popupMenuAssign= new JPopupMenu();
		addPopup(tableAssign, popupMenuAssign);
		
		 mntmBorrarAssign = new JMenuItem(rb.getString("borrar"));
		 mntmBorrarAssign.addActionListener(new ActionListener() {
			
			 @Override
				public void actionPerformed(ActionEvent arg0) {
					int row = tableAssign.getSelectedRow();
					Object [][] obj = masa.getFilas();
					int idBorrar = (int) obj[row][6];
					EliminarImpartirAssignatura ea = new EliminarImpartirAssignatura();
					ea.eliminarRegistre(idBorrar, tableAssign.getValueAt(row, 0).toString());

					masa.setSql(sqlAS);
					dtmEjemplo = new DefaultTableModel(masa.getFilas(), masa.getColumnas()){

						@Override
						public boolean isCellEditable(int arg0, int arg1) {
							return false;
						}
						
					};
					tableAssign.setModel(dtmEjemplo);
				}
		});
		popupMenuAssign.add(mntmBorrarAssign);
		
		/**
		 * Dia
		 */
		JLabel lblDia = new JLabel(rb.getString("lblDia"));
		GridBagConstraints gbc_lblDia = new GridBagConstraints();
		gbc_lblDia.anchor = GridBagConstraints.EAST;
		gbc_lblDia.insets = new Insets(0, 0, 5, 5);
		gbc_lblDia.gridx = 0;
		gbc_lblDia.gridy = 4;
		add(lblDia, gbc_lblDia);
		
		comboDia = new JCalendarCombo();
		comboDia.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				Date date = comboDia.getDate();
				SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
				fecha = sdf.format(date);
				
			}
		});
		GridBagConstraints gbc_comboBox = new GridBagConstraints();
		gbc_comboBox.gridwidth = 3;
		gbc_comboBox.insets = new Insets(0, 0, 5, 5);
		gbc_comboBox.fill = GridBagConstraints.HORIZONTAL;
		gbc_comboBox.gridx = 1;
		gbc_comboBox.gridy = 4;
		add(comboDia, gbc_comboBox);
		
		JLabel lblHora = new JLabel(rb.getString("lblHora"));
		GridBagConstraints gbc_lblHora = new GridBagConstraints();
		gbc_lblHora.anchor = GridBagConstraints.EAST;
		gbc_lblHora.insets = new Insets(0, 0, 5, 5);
		gbc_lblHora.gridx = 0;
		gbc_lblHora.gridy = 5;
		add(lblHora, gbc_lblHora);
		
		
		int hora, minuts, segons;
		Calendar calendari = new GregorianCalendar();
		hora = calendari.get(Calendar.HOUR_OF_DAY);
		minuts = calendari.get(Calendar.MINUTE);
		segons = calendari.get(Calendar.SECOND);
		horaAct = hora+":"+minuts+":"+segons;
		
		txtHora = new JTextField(horaAct);
		txtHora.setText(horaAct);
		GridBagConstraints gbc_formattedTextField = new GridBagConstraints();
		gbc_formattedTextField.gridwidth = 3;
		gbc_formattedTextField.insets = new Insets(0, 0, 5, 5);
		gbc_formattedTextField.fill = GridBagConstraints.HORIZONTAL;
		gbc_formattedTextField.gridx = 1;
		gbc_formattedTextField.gridy = 5;
		add(txtHora, gbc_formattedTextField);
		
		/**
		 * eleccio tipus assistencia
		 */
		JLabel lblTipus = new JLabel(rb.getString("lblTipus"));
		GridBagConstraints gbc_lblTipus = new GridBagConstraints();
		gbc_lblTipus.insets = new Insets(0, 0, 5, 5);
		gbc_lblTipus.gridx = 0;
		gbc_lblTipus.gridy = 6;
		add(lblTipus, gbc_lblTipus);
		
		ButtonGroup group = new ButtonGroup();
		
		rdbtnAssistit = new JRadioButton(rb.getString("radioAssistit"));
		GridBagConstraints gbc_rdbtnAssistit = new GridBagConstraints();
		gbc_rdbtnAssistit.insets = new Insets(0, 0, 5, 5);
		gbc_rdbtnAssistit.gridx = 1;
		gbc_rdbtnAssistit.gridy = 6;
		add(rdbtnAssistit, gbc_rdbtnAssistit);
		group.add(rdbtnAssistit);
		
		rdbtnRetard = new JRadioButton(rb.getString("radioRetard"));
		GridBagConstraints gbc_rdbtnRetard = new GridBagConstraints();
		gbc_rdbtnRetard.insets = new Insets(0, 0, 5, 5);
		gbc_rdbtnRetard.gridx = 1;
		gbc_rdbtnRetard.gridy = 7;
		add(rdbtnRetard, gbc_rdbtnRetard);
		group.add(rdbtnRetard);
		
		rdbtnFalta = new JRadioButton(rb.getString("radioFalta"));
		GridBagConstraints gbc_rdbtnFalta = new GridBagConstraints();
		gbc_rdbtnFalta.insets = new Insets(0, 0, 5, 5);
		gbc_rdbtnFalta.gridx = 1;
		gbc_rdbtnFalta.gridy = 8;
		add(rdbtnFalta, gbc_rdbtnFalta);
		group.add(rdbtnFalta);
		
		rdbtnFaltaJustificada = new JRadioButton(rb.getString("radioJustific"));
		GridBagConstraints gbc_rdbtnFaltaJustificada = new GridBagConstraints();
		gbc_rdbtnFaltaJustificada.insets = new Insets(0, 0, 5, 5);
		gbc_rdbtnFaltaJustificada.gridx = 1;
		gbc_rdbtnFaltaJustificada.gridy = 9;
		add(rdbtnFaltaJustificada, gbc_rdbtnFaltaJustificada);
		group.add(rdbtnFaltaJustificada);
		
		/**
		 * comentari
		 */
		JLabel lblComentari = new JLabel(rb.getString("lblComentari"));
		GridBagConstraints gbc_lblComentaril = new GridBagConstraints();
		gbc_lblComentaril.insets = new Insets(0, 0, 5, 5);
		gbc_lblComentaril.gridx = 0;
		gbc_lblComentaril.gridy = 10;
		add(lblComentari, gbc_lblComentaril);
		
		textPane = new JTextPane();
		scrollComen = new JScrollPane();
		scrollComen.setViewportView(textPane);
		GridBagConstraints gbc_textPane = new GridBagConstraints();
		gbc_textPane.gridwidth = 4;
		gbc_textPane.insets = new Insets(0, 0, 5, 0);
		gbc_textPane.fill = GridBagConstraints.BOTH;
		gbc_textPane.gridx = 1;
		gbc_textPane.gridy = 10;
		add(scrollComen, gbc_textPane);
		
		/**
		 * botons finals
		 */
		JButton btnCancelar = new JButton(rb.getString("btnCancelar"));
		btnCancelar.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				tableAlum.changeSelection(0, 0, false, true);
				tableAssign.changeSelection(0, 0, false, true);
				int hora, minuts, segons;
				Calendar calendari = new GregorianCalendar();
				hora = calendari.get(Calendar.HOUR_OF_DAY);
				minuts = calendari.get(Calendar.MINUTE);
				segons = calendari.get(Calendar.SECOND);
				horaAct = hora+":"+minuts+":"+segons;
				txtHora.setText(horaAct);
				textPane.setText(null);
			}
		});
		GridBagConstraints gbc_btnCancelar = new GridBagConstraints();
		gbc_btnCancelar.insets = new Insets(0, 0, 0, 5);
		gbc_btnCancelar.gridx = 3;
		gbc_btnCancelar.gridy = 11;
		add(btnCancelar, gbc_btnCancelar);
		
		JButton btnGuardar = new JButton(rb.getString("btnGuardar"));
		btnGuardar.addActionListener(new ActionListener() {
			
			@Override
			public void actionPerformed(ActionEvent arg0) {
				/**
				 * comprobacions radio
				 */
				boolean seguirRadio = false;
				String radioSelec = null;
				if(rdbtnAssistit.isSelected()){
					seguirRadio = true;
					radioSelec = "Assistit";
				}else if(rdbtnRetard.isSelected()){
					seguirRadio = true;
					radioSelec = "Retard";
				}
				else if(rdbtnFalta.isSelected()){
					seguirRadio = true;
					radioSelec = "Falta";
				}
				else if(rdbtnFaltaJustificada.isSelected()){
					seguirRadio = true;
					radioSelec = "Falta_Justificada";
				}
				
				boolean seguir = false;
				/**
				 * comprobacions 
				 */
				if(tableAlum.getSelectedRow() < 0){
					seguir = false;
					JOptionPane.showMessageDialog(null,
							rb.getString("missatgeTriaAssignatura"),
							rb.getString("titolFaltenDades"),
							JOptionPane.ERROR_MESSAGE);
				}else{
					seguir=true;
					if(tableAssign.getSelectedRow() < 0){
						seguir = false;
						JOptionPane.showMessageDialog(null,
								rb.getString("missatgeTriaAlumne"),
								rb.getString("titolFaltenDades"),
								JOptionPane.ERROR_MESSAGE);
					}else{
						seguir = true;
						if(txtHora.getText().matches("[0-9][0-9]:[0-9][0-9]:[0-9][0-9]")){
							seguir = true;
						}else{
							seguir = false;
							JOptionPane.showMessageDialog(null,
									rb.getString("missatgeHoraFiIncorrecta"),
									rb.getString("titolHoraIncorrecta"),
									JOptionPane.ERROR_MESSAGE);
							if(seguirRadio == true){
								seguir = true;
								if(fecha != null){
									seguir = true;
								}else{
									seguir = false;
									JOptionPane.showMessageDialog(null,
											rb.getString("missatgeSeleccionaFecha"),
											rb.getString("titolFaltenDades"),
											JOptionPane.ERROR_MESSAGE);
								}
							}else{
								seguir = false;
								JOptionPane.showMessageDialog(null,
										rb.getString("missatgeSeleccionaRadio"),
										rb.getString("titolFaltenDades"),
										JOptionPane.ERROR_MESSAGE);
								
							}
						}
					}
				}
				
				if(seguir == true){
					if(txtHora.getText() == null)
						txtHora.setText(horaAct);
					
					int row2 = tableAssign.getSelectedRow();
					Object [][] obj2 = masa.getFilas();
					int idImpartir = (int) obj2[row2][6];
					
					InserirAssistencia ias = new InserirAssistencia();
					
					boolean insCorrect = ias.insertManual(idAlum, idImpartir, txtHora.getText(), fecha, radioSelec ,textPane.getText());
					
					if(insCorrect == false){
						JOptionPane.showMessageDialog(null,
								rb.getString("missatgeErrorInsercio"),
								rb.getString("titolErrorInsercio"),
								JOptionPane.ERROR_MESSAGE);
					}else{
						JOptionPane.showMessageDialog(null,
								rb.getString("missatgeDadesInsertades"),
								rb.getString("titolDadesInsertades"),
								JOptionPane.INFORMATION_MESSAGE);
						tableAlum.changeSelection(0, 0, false, true);
						tableAssign.changeSelection(0, 0, false, true);
						int hora, minuts, segons;
						Calendar calendari = new GregorianCalendar();
						hora = calendari.get(Calendar.HOUR_OF_DAY);
						minuts = calendari.get(Calendar.MINUTE);
						segons = calendari.get(Calendar.SECOND);
						horaAct = hora+":"+minuts+":"+segons;
						txtHora.setText(horaAct);
						textPane.setText(null);
					}
				}
			}
		});
		GridBagConstraints gbc_btnGuardar = new GridBagConstraints();
		gbc_btnGuardar.gridx = 4;
		gbc_btnGuardar.gridy = 11;
		add(btnGuardar, gbc_btnGuardar);
		

	}
	

	private int veureIdAnyAncademic(){
		int idAny = 0;
		PreferenciesAnyAcademic paa = new PreferenciesAnyAcademic();
		idAny = paa.getAnyAcademic();
		
		return idAny;
	}
	

	private static void addPopup(Component component, final JPopupMenu popup) {
		component.addMouseListener(new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			public void mouseReleased(MouseEvent e) {
				if (e.isPopupTrigger()) {
					showMenu(e);
				}
			}
			private void showMenu(MouseEvent e) {
				popup.show(e.getComponent(), e.getX(), e.getY());
			}
		});
	}
	
}
